<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>全选全不选反选</title>
</head>
<body>
<form action="">
  <p><input id="" name="" type="checkbox">吃饭</p>
  <p><input id="" name="" type="checkbox">睡觉</p>
  <p><input id="" name="" type="checkbox">打豆豆</p>
</form>
<button onclick="getAllChecked(1)">全选</button>
<button onclick="getAllChecked(2)">全不选</button>
<button onclick="getAllChecked(3)">反选</button>
</body>
<script>
  let inputs = document.getElementsByTagName('input');

  function getAllChecked(num) {
    if (num === 1) {
      for (let i = 0; i < inputs.length; i++) {
        inputs[i].checked = true;
      }
    } else if (num === 2) {
      for (let i = 0; i < inputs.length; i++) {
        inputs[i].checked = false;
      }
    } else {
      for (let i = 0; i < inputs.length; i++) {
        inputs[i].checked = !inputs[i].checked;
      }
    }
  }
</script>
</html>